package com.internetCafes.spms.web.sys.controller;

import com.internetCafes.spms.common.module.excel.ExcelUtils;
import com.internetCafes.spms.common.utils.entity.RR;
import com.internetCafes.spms.common.utils.entity.page.PageItemDTO;
import com.internetCafes.spms.common.utils.entity.page.PageItemVO;
import com.internetCafes.spms.web.tenant.bizservice.ITenantInfoPlusBizService;
import com.internetCafes.spms.web.tenant.model.req.TenantCountPagingReq;
import com.internetCafes.spms.web.tenant.model.res.TenantInfoPlusRes;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 统计前端控制器
 *
 * @author Zj
 * @date 2021/12/7 15:44
 */
@RestController
@RequestMapping("/sys/count")
public class SysCountController {

    @Autowired
    ITenantInfoPlusBizService iTenantInfoPlusBizService;

    /**
     * 企业信息统计数据
     */
    @PostMapping("/tenant/paging")
//    @RequiresPermissions("sys:count:tenantInfo")
    public RR<PageItemVO<TenantInfoPlusRes>> countPaging(@RequestBody PageItemDTO<TenantCountPagingReq> req) {
        return RR.success(iTenantInfoPlusBizService.pagingCount(req));
    }

    /**
     * 企业证书信息统计导出
     */
    @RequestMapping("/tenant/export")
//    @RequiresPermissions("sys:count:export")
    public void export(HttpServletResponse response, TenantCountPagingReq conditionsReq) {
        Workbook workbook = iTenantInfoPlusBizService.exportCount(conditionsReq);
        ExcelUtils.downLoadExcel("tenantCertificateCount.xls", response, workbook);
    }

}
